package com.itgungnir.diyshuo.fragment.danpin_fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.GridView;
import android.widget.Toast;

import com.handmark.pulltorefresh.library.PullToRefreshGridView;
import com.itgungnir.diyshuo.activity.R;
import com.itgungnir.diyshuo.adapter.DanPinAdapter;
import com.itgungnir.diyshuo.base.BaseFragment;
import com.itgungnir.diyshuo.bean.GoodsBean;

import java.util.List;

/**
 * 展示“单品”页面的Fragment
 */
public class DanPinFragment extends BaseFragment implements DanPinContract.View {
    PullToRefreshGridView mPullToRefreshGridView;
    private GridView mGridView;
    private Button button;
    private DanPinPresenter presenter;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_danpin;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mPullToRefreshGridView= (PullToRefreshGridView) view.findViewById(R.id.danpin_gv);
        button= (Button) view.findViewById(R.id.danpin_btn_search);
        presenter=new DanPinPresenter(this);
        presenter.getDanPinFromNet(null);
        mGridView=mPullToRefreshGridView.getRefreshableView();

    }



    @Override
    public void onDanPinSuccess(List<GoodsBean> goodsBeanList) {

        DanPinAdapter adapter=new DanPinAdapter(getActivity(),goodsBeanList);
        mGridView.setAdapter(adapter);
    }

    @Override
    public void onDanPinFail(String msg) {
        Toast.makeText(getActivity(),"数据加载失败...",Toast.LENGTH_SHORT).show();
    }
}